<template>
  <div class="zs-table-page-container">
    <div class="zs-card-sm zs-space-bottom zs-layout-flex-row zs-layout-justify-between">
      <span>
        <el-select v-model="curPlatId" class="zs-select-md zs-space-right-sm" placeholder="平台商名称" clearable filterable>
          <el-option v-for="item in platList" :key="item.companyPlatformId" :label="item.companyPlatformName" :value="item.companyPlatformId" />
        </el-select>
        <el-button class="zs-btn-plain" @click="getList()">
          查询
        </el-button>
      </span>
    </div>
    <div class="zs-card zs-table-page-content">
      <el-table :data="tableData" class="zs-tabel-page-main-no-footer" :stripe="true" v-loading="loading">
        <el-table-column type="index" label="序号" width="60" :align="'center'" />
        <el-table-column prop="companyPlatformName" label="平台商" :align="'left'" width="260" />
        <el-table-column label="订单金额" :align="'right'">
          <template #default="scope">
            {{ toThousands(scope.row.orderPrice) }}
          </template>
        </el-table-column>
        <el-table-column label="增值收入" :align="'right'">
          <template #default="scope">
            {{ toThousands(scope.row.dividePriceAll) }}
          </template>
        </el-table-column>
        <el-table-column label="分佣金额" :align="'right'">
          <template #default="scope">
            {{ toThousands(scope.row.dividePriceSum) }}
          </template>
        </el-table-column>
        <el-table-column label="操作" :align="'right'" width="100">
          <template #default="scope">
            <el-button class="zs-link" link size="small" @click="goPage(scope.row)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="zs-text-gray-dark zs-text-sm zs-space-top">*单位：万元</div>
    </div>
  </div>
</template>
<script setup>
import dbPublicApi from '@/api/dbPublic'
import dashBoardApi from '@/api/EnterpriseServices/dashBoard'
import { toThousands } from '@/utils/number-util'
import { ref } from 'vue'
import { useRouter } from 'vue-router'
const router = useRouter()

let curPlatId = ref('')
let platList = ref([])
const loading = ref(false)
// let tag = ref('')
const updateDate = ref('')
const tableData = ref([])

const getDate = async () => {
  await dbPublicApi.queryDataTimeApi().then((res) => {
    if (res.data.code == 200) {
      // tag.value = res.data.message
      updateDate.value = res.data.data
    }
  })
}

const getPlatList = () => {
    dashBoardApi.getCompanyPlatformListApi().then((res) => {
        if (res.data.code == 200) {
            platList.value = res.data.data
        }
    })
}

const getList = () => {
  loading.value = true
  tableData.value = []
  dashBoardApi.platformListApi({ companyPlatformId: curPlatId.value, dataTime: updateDate.value, pageNo: 1, pageSize: 10000 }).then((res) => {
    if (res.data.code == 200) {
      // if(curPlatId.value == '') {
      //   platList.value = res.data.data
      // }
      tableData.value = res.data.data
      loading.value = false
    }
  })
}

const goPage = (row) => {
  router.push({
    path: '/page/routeController/index',
    query: {
      rid: 'dashboard/enterpriseServicesDashboard',
      rTitle: '企业服务-详情',
      companyPlatformId: row.companyPlatformId,
      updateDate: updateDate.value,
    },
  })
}

const init = async () => {
  getPlatList()
  await getDate()
  getList()
}
init()

</script>


<style scoped lang="scss"></style>
